class GameConfig < ActiveRecord::Base
  belongs_to    :player
  
  def GameConfig.singleton
    @@config = GameConfig.find_or_create_by_id(1) unless @config
    return @@config
  end
  
  def GameConfig.admin_player
    GameConfig.singleton.player
  end
  
  def GameConfig.set_admin_player (player)
    config = GameConfig.singleton
    config.player_id = player.id
    config.save
  end
  
  def GameConfig.current_date
    GameConfig.singleton.current_date
  end
  
  def GameConfig.increment_date
    config = GameConfig.singleton
    config.current_date += 1
    config.save
    return config.current_date
  end
  
  def GameConfig.month_names
    [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"
    ]
  end
  
  def GameConfig.display_date (date=GameConfig.current_date)
    return nil unless date
    year = 1000 + (date / 365)
    month = ((date % 365) / 12)
    day = ((date % 365) % 12) + 1
    month_name = GameConfig.month_names[month]
    "#{day} of #{month_name}, #{year}AD"
  end
end
